# -*- coding = utf-8 -*-
"""
# @Author       :   howtime
# @CreateTime   :   2022/2/15
# @File         :   decimal_arithmetic.py
# @Desc         :   ...
# @Version      :   v0.0
# @Update       :   2022/2/15
"""
from typing import Union
from decimal import Decimal as DC, ROUND_HALF_UP


def rounding(num: Union[str, DC, float, int], prec: int = 2) -> str:
    if not num and num != 0:
        return ''
    elif isinstance(num, str) and (',' in num or '，' in num):
        return num
    elif isinstance(num, str):
        num = DC(num)
    elif isinstance(num, (float, int)):
        num = DC(str(num))
    else:
        pass
    return str(num.quantize(DC(f"0.{''.join(['0' for _ in range(prec)])}"), rounding=ROUND_HALF_UP))
